﻿using System.Collections.Generic;
using System.Windows.Forms;
using Com.Enterprisecoding.TFS.CheckInNotifier.EventData;

namespace Com.Enterprisecoding.TFS.CheckInNotifier {
    public partial class FileListingDialog : Form {
        public FileListingDialog(ClientArtifact[] clientArtifacts) {
            InitializeComponent();

            var versionedItems = new List<ClientArtifact>();

            foreach (var clientArtifact in clientArtifacts) {
                if (clientArtifact.ArtifactType == "VersionedItem") {
                    versionedItems.Add(clientArtifact);
                }
            }

            artifacts.DataSource = versionedItems.ToArray();
        }

        private void artifacts_CellClick(object sender, DataGridViewCellEventArgs e) {
            if (e.RowIndex < 0 || e.ColumnIndex != artifacts.Columns["openArtifactColumn"].Index) { return; }

            var clientArtifact = (ClientArtifact)artifacts.Rows[e.RowIndex].DataBoundItem;

            new BrowserDialog(clientArtifact.Url).ShowDialog(this);
        }
    }
}
